/**
 * 首页
 */
v_index = new Vue({
	el: '#homePage',
	data: {
		title: '',
		needBack: false,
		needRefresh: false,
		navs: $.extend(true, [], navs, [{active: 'active'}]),
		agent: {},
		totalGoodsCount: 0,
		selfSales: [{
			title: '当日销量',
			icon: 'icon-xiaoshou',
			amount: '￥0',
			bg: 'bg-danger',
			style: {
				'margin-left': '1%',
				width: '32%'
			}
		},{
			title: '当月销量',
			icon: 'icon-6xiaoliang',
			amount: '￥0',
			bg: 'bg-success',
			style: {
				'margin-left': '1%',
				width: '32%'
			}
		},{
			title: '累计销量',
			icon: 'icon-xiaoliangyuce',
			amount: '￥0',
			bg: 'bg-primary',
			style: {
				'margin-left': '1%',
				width: '32%'
			}
		}],
		teamSales: [{
			title: '团队当日销量',
			icon: 'icon-meirixiaoshoubaobiao',
			amount: '￥0',
			bg: 'bg-danger',
			style: {
				'margin-left': '0',
				width: '33%'
			}
		},{
			title: '团队当月销量',
			icon: 'icon-xiaoshoubaobiao2',
			amount: '￥0',
			bg: 'bg-success',
			style: {
				'margin-left': '0',
				width: '33%'
			}
		},{
			title: '团队累计销量',
			icon: 'icon-xiaoshoubaobiao',
			amount: '￥0',
			bg: 'bg-primary',
			style: {
				'margin-left': '0',
				width: '33%'
			}
		}],
		awardes: [{
			title: '当月团队奖金',
			icon: 'icon-tuandui',
			amount: '￥0',
			bg: 'bg-primary',
			style: {
				'margin-left': '0',
				width: '50%'
			}
		},{
			title: '当月我的奖金',
			icon: 'icon-iconfontjinlingyingcaiwangtubiao30',
			amount: '￥0',
			bg: 'bg-info',
			style: {
				'margin-left': '0',
				width: '50%'
			}
		}]
	},
	created: function() {
		axios.post('/agent/current')
		.then(function(resp) {
			if (resp.data.success) {
				v_index.agent = resp.data.message;
				if (!v_index.agent.headUrl) {
					v_index.agent.headUrl = v_index.agent.sex ? '/images/header_male.png' : '/images/header_female.png';
				}
			}
		})
		.catch(function (error) {
			console.log(error);
		});
		axios.post('/agent/sales/current')
		.then(function(resp) {
			if (resp.data.success) {
				var sales = resp.data.message;
				v_index.selfSales[0].amount = sales.daySales_fmt;
				v_index.selfSales[1].amount = sales.monthSales_fmt;
				v_index.selfSales[2].amount = sales.totalSales_fmt;
			}
		})
		.catch(function (error) {
			console.log(error);
		});
		
		axios.post('/agent/sales/current/team')
		.then(function(resp) {
			if (resp.data.success) {
				var sales = resp.data.message;
				v_index.teamSales[0].amount = sales.daySales_fmt;
				v_index.teamSales[1].amount = sales.monthSales_fmt;
				v_index.teamSales[2].amount = sales.totalSales_fmt;
			}
		})
		.catch(function (error) {
			console.log(error);
		});
		
		axios.post('/agent/award/current')
		.then(function(resp) {
			if (resp.data.success) {
				var sales = resp.data.message;
				v_index.awardes[1].amount = sales.monthAmount_fmt;
			}
		})
		.catch(function (error) {
			console.log(error);
		});
		
		axios.post('/agent/award/current/team')
		.then(function(resp) {
			if (resp.data.success) {
				var sales = resp.data.message;
				v_index.awardes[0].amount = sales.monthAmount_fmt;
			}
		})
		.catch(function (error) {
			console.log(error);
		});
	}
});
